package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.example.myapplication.ui.theme.MyApplicationTheme

class TestActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        setContent {
            MyApplicationTheme(false) {
                BaoMaColor()
            }
        }
    }
}

@Composable
fun BaoMaColor(){
    Surface(modifier = Modifier.background(Color(R.color.m_white)), color = Color(R.color.m_white)) {

        Column() {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                ComposableInfoCard(
                    title = "123",
                    description = "456",
                    backgroundColor = Color(0xffffffff),
                    modifier = Modifier.weight(1f)
                )
                Text(
                    text = "Hello",
                    modifier = Modifier
                        .background(Color.Blue)
                        .weight(1f)
                        .fillMaxHeight()
                )
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Text(
                    text = "Hello",
                    modifier = Modifier
                        .background(Color.Blue)
                        .weight(1f)
                        .fillMaxHeight()
                )
                Text(
                    text = "Hello jiahe",
                    modifier = Modifier
                        .background(Color.White)
                        .weight(1f)
                        .fillMaxHeight()
                )
            }

            Text(text = "Hello", modifier = Modifier.fillMaxHeight().fillMaxWidth().background(Color.Red).weight(1f))
        }
    }
}

@Preview
@Composable
fun PreviewContent() {

    BaoMaColor()
}

@Composable
private fun ComposableInfoCard(
    title: String,
    description: String,
    backgroundColor: Color,
    modifier: Modifier = Modifier
) {
    Column(
        modifier = modifier
            .fillMaxSize()
            .background(backgroundColor)
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        Text(
            text = title,
            fontWeight = FontWeight.Bold,
            modifier = Modifier.padding(bottom = 16.dp)
        )
        Text(
            text = description,
            textAlign = TextAlign.Justify
        )
    }
}